// pages/confirm/confirm.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:'',
    number:'',
    classroom:'',
    dates:'',
    time:'',
    type:'',
    reason:'',
    activetype:'',
    start:'',
    end:''
  },
  toReturn: function(){
    wx.navigateBack()
  },
  toConfirm: function(){
    wx.request({
      url:'https://yali.geekwhite.cn:3000/submit', 
      // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        name:this.data.name,
        number:this.data.number,
        classroom:this.data.classroom,
        dates:this.data.dates,
        time:this.data.time,
        start:this.data.start,
        end:this.data.end,
        type:this.data.type,
        reason:this.data.reason,
        activetype:this.data.activetype
       },
       method: 'post',
       success: function (res) {
            // console.log(data);
            console.log(res.data);
            if(res.data){
              wx.navigateTo({
                url: '../checkshow/checkshow',
              })
              wx.showModal({
                title: '提示',
                content: '申请已提交',
                success: function (res) {
                  if (res.confirm) {//这里是点击了确定以后
                    console.log('用户点击确定')
                  } else {//这里是点击了取消以后
                    console.log('用户点击取消')
                  } 
                }
              })
            }
            else{
              wx.showModal({
                title: '提示',
                content: '该时间段教室已被占用',
                success: function (res) {
                  if (res.confirm) {//这里是点击了确定以后
                    console.log('用户点击确定')
                  } else {//这里是点击了取消以后
                    console.log('用户点击取消')
                  } 
                }
              })
            }
            
       }
    })
    // wx.navigateBack({
    //   delta: 10,
    // })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      name:options.name,
      number:options.number,
      classroom:options.classroom,
      dates:options.date,
      time:options.time+'-'+options.time1,
      start:options.time,
      end:options.time1,
      type:options.type,
      reason:options.reason,
      activetype:options.activetype

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})